package bh
import java.text.SimpleDateFormat
import java.util.*


object FS {

    @JvmStatic
    fun getNowHour(): Int {
        return Calendar.getInstance().get(Calendar.HOUR_OF_DAY)
    }

    /**
     * HH:mm
     */
    fun getNowTime(): String {
        val simpleDateFormat = SimpleDateFormat("HH:mm")
        // 获取当前时间
        val date = Date(System.currentTimeMillis());
        return simpleDateFormat.format(date)
    }


    /**
     * yyyy-MM-dd
     * @param time
     * @return
     */
    @JvmStatic
    fun long2DateSimple(time: Long): String? {
        var time = time
        if (time < 100) time = System.currentTimeMillis()
        val c = Calendar.getInstance()
        c.timeInMillis = time
        val formatter = SimpleDateFormat("yyyy-MM-dd")
        return formatter.format(c.time)
    }

    private val weeks = arrayOf("周日", "周一", "周二", "周三", "周四", "周五", "周六")

    @JvmStatic
    fun getWeekDay(position: Int = 3, date: String): String {
        return when (position) {
            0 -> {
                "今天"
            }
            1 -> {
                "明天"
            }
            2 -> {
                "后天"
            }
            else -> {
                val calendar = Calendar.getInstance()
                val dateArray = date.split("-")
                calendar.set(dateArray[0].toInt(), dateArray[1].toInt() - 1, dateArray[2].toInt())
                var w = calendar.get(Calendar.DAY_OF_WEEK) - 1
                if (w < 0) {
                    w = 0
                }
                weeks[w]
            }
        }
    }
}